package com.lovo.lesson1.Freme;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyFrame extends JFrame {
    private JTextField fisrtTime,seonendTime;
    private JButton bnt;

    public MyFrame(){
        this.setTitle("没得");
        this.setBounds(100,100,700,600);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);

        fisrtTime = new JTextField();
        fisrtTime.setBounds(30,30,100,50);

        seonendTime = new JTextField();
        seonendTime.setBounds(30,100,100,50);

        bnt = new JButton();
        bnt.setText("计算");
        bnt.setBounds(30,160,100,50);

        bnt.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String str1 = fisrtTime.getText();
                String str2 = seonendTime.getText();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    Date d1 = sdf.parse(str1);
                    Date d2 = sdf.parse(str2);

                    double t =(d2.getTime() - d1.getTime())/(1000*60*60*24);
                    JOptionPane.showMessageDialog(null,t);
                } catch (ParseException parseException) {
                    JOptionPane.showMessageDialog(null,"滚呐");
                    fisrtTime.setText(" ");
                    seonendTime.setText(" ");
                }
            }
        });

        add(fisrtTime);
        add(seonendTime);
        add(bnt);
    }
}
